--规行矩止
local guixingjuzhi = fk.CreateSkill {
    name = "mcdh_guixingjuzhi"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

guixingjuzhi:addEffect(fk.EventPhaseStart,{
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(self) and target == player and (player.phase == Player.Start or player.phase == Player.Finish)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        if player.phase == Player.Start then
            local targets = table.filter(room.alive_players, function(p)
                return not p:isKongcheng() end)
                local to =room:askToChoosePlayers(player, {
                    targets = targets,
                    min_num = 1,
                    max_num = 1,
                    prompt = "#guixingjuzhi-choose1",
                    skill_name = self.name,
                    cancelable = true
                  })
            if #to > 0 then
                self.cost_data = to[1]
                return true
            end
        elseif player.phase == Player.Finish then
            local to =room:askToChoosePlayers(player, {
                targets = room.alive_players,
                min_num = 1,
                max_num = 1,
                prompt = "#guixingjuzhi-choose2",
                skill_name = self.name,
                cancelable = true
              })
            if #to > 0 then
                self.cost_data = to[1]
                return true
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        if player.phase == Player.Start then
            local to = self.cost_data
            local id = room:askForCardChosen(player, to, "h", self.name)
            room:throwCard({id}, self.name, to, player)
        elseif player.phase == Player.Finish then
            local to = self.cost_data
            local choice = room:askForChoice(player, {"1","2"}, self.name, "#guixingjuzhi-draw:"..to.id)
            to:drawCards(tonumber(choice),self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_guixingjuzhi"] = "规止",
    [":mcdh_guixingjuzhi"] = "『规行矩止』<br>准备阶段，你可以弃置一名角色的一张手牌；结束阶段，你可以令一名角色摸至多两张牌。",
    ["#guixingjuzhi-choose1"] = "规行矩止:弃置一名角色的一张手牌",
    ["#guixingjuzhi-choose2"] = "规行矩止:令一名角色摸至多两张牌",
    ["#guixingjuzhi-draw"] = "规行矩止:令 %src 摸至多两张牌"
}



return guixingjuzhi